package buber.data;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import buber.exceptions.BadDataException;
import buber.exceptions.ImportException;


public class FileImport implements DataImport{
	private DataSet data;
	public FileImport(String fileName) throws ImportException{
		try {
			BufferedReader inFile = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName))));
			StringBuffer sb = new StringBuffer();
			String line="";
			try {
				while((line = inFile.readLine())!=null){
					sb.append(line);
				}
				data.build(sb.toString());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				throw new ImportException();
			} catch (BadDataException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			throw new ImportException();
		}
	}
	public DataSet getDataSet() throws ImportException {
		return data;
	}
	public DataSet getDataSetById(Long id) throws ImportException {
		return data;
	}
	public String getDataString() throws ImportException {
		return data.asString();
	}
	
}
